from io import BytesIO
from uuid import uuid4

from app.api.human_input_handle import get_thread_identifier
from app.graph import DataRequirementAnalysisWorkflow


from app.models import SessionState


# 输入处理函数


if __name__ == "__main__":
    #visualize_graph(workflow)
    workflow = DataRequirementAnalysisWorkflow()


    initial_state: SessionState={
        "original_input": None,
        "input_type": None,
        "require_clearness": None,
        "clarify_input": None,
        "require_json": None,
        "field_availability": None,
        "field_json": None,
        "process_solution": None,
        "collect_solution": None,
        "change_or_not": None,
        "next": None,  # 初始不指定下一步，由流程逻辑决定
        "messages": [] ,# 消息列表初始化为空列表
        "user_initial_input": None ,  #
        "missing_fields": None,  # 缺失字段信息
        "user_require":[],
        "user_loop_count":0, #用户多次更新字段需求最大次数，暂定最大3次
        "user_satisfaction_intention":0, #用户满意程度意图标识，0为不满意，1为满意
        "user_update_fileds":None #用于存储提取出来的字段信息
    }
    thread_id = get_thread_identifier()
    config = {"configurable": {"thread_id": thread_id}}

    workflow.run(initial_state, config)